package cn.topevery.garden.dal.dao.impl;

import cn.topevery.garden.dal.dao.WxScoreDao;
import cn.topevery.garden.entity.po.WxScore;
import cn.topevery.garden.entity.query.WxScoreQuery;
import cn.topevery.garden.entity.vo.WxScoreVO;
import cn.topevery.garden.framework.base.BaseDaoImpl;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.entity.DbCsp;
import hw.topevery.framework.entity.KeyValue;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 
 *
 * @author code-generate
 * @date 2022-01-10
 */
@Repository
public class WxScoreDaoImpl extends BaseDaoImpl<WxScore> implements WxScoreDao {
    @Override
    public <P extends DbCsp> List<WxScore> getSearch(P para) {
        return null;
    }

    

    @Override
    public DataPager<WxScoreVO> listPage(WxScoreQuery query) {
        String table = "t_wx_score tws";

        String columns = "score.c_openid      AS openid,\n" +
                "               score.c_nickname    AS nickname,\n" +
                "               (\n" +
                "                   SELECT count(1)\n" +
                "                   FROM t_wx_score AS exercise\n" +
                "                   WHERE exercise.c_db_status = 0\n" +
                "                     AND exercise.c_reward_type = 1\n" +
                "                   GROUP BY exercise.c_openid,\n" +
                "                            exercise.c_nickname\n" +
                "                   HAVING exercise.c_openid = score.c_openid\n" +
                "               )                  AS exercise,\n" +
                "               (\n" +
                "                   SELECT count(1)\n" +
                "                   FROM t_wx_score AS exercise\n" +
                "                   WHERE exercise.c_db_status = 0\n" +
                "                     AND exercise.c_reward_type = 2\n" +
                "                   GROUP BY exercise.c_openid,\n" +
                "                            exercise.c_nickname\n" +
                "                   HAVING exercise.c_openid = score.c_openid\n" +
                "               )                  AS questionnaire,\n" +
                "               SUM(score.c_score) AS totalScore    GROUP BY score.c_openid,\n" +
                "                 score.c_nickname";

        int pageIndex = query.pageIndex - 1;
        int pageSize = query.pageSize;

        return getDataPager(null, pageSize, pageIndex, WxScoreVO.class);
    }

    @Override
    public WxScore getEntityByColumn(String key,String value){
        KeyValue<String> map=new KeyValue<>();
        map.key=key;
        map.value=value;
        return getEntityByColumnEqValue(map);
    }
}
